﻿using System;
using System.Text;
using UnityEngine;
using UnityEngine.UI;
using FrameOperateSync;

public class TransformGame : MonoBehaviour
{
    [SerializeField] private Text frameInfo;
    [SerializeField] private Transform cube1;
    [SerializeField] private Transform cube2;

    private StringBuilder debugStringBuilder = new StringBuilder();
    private void Awake()
    {
        FrameSyncCenter.RegistRenderHander(OnRender1);
        FrameSyncCenter.RegistRenderHander(OnRender2);
    }
    private void OnDestroy()
    {
        FrameSyncCenter.UnRegistRenderHander(OnRender1);
        FrameSyncCenter.UnRegistRenderHander(OnRender2);

    }


    [FrameRender((int)OperateType.op1, typeof(OperateData1), "测试1")]
    public void OnRender1(int playerId, int keyFrameIndex, int frameIndex, IRenderData operateData)
    {
        string info = $"当前逻辑:type = {operateData.GetType().ToString()},keyFrame = {keyFrameIndex},frameIndex = {frameIndex}";
        debugStringBuilder.Append(info);
        var renderData = operateData as OperateData1;
        //Debug.
        cube1.localPosition = new Vector3(renderData.x_pos, cube1.localPosition.y, renderData.y_pos);
    }

    [FrameRender((int)OperateType.op2, typeof(OperateData2), "测试2")]
    public void OnRender2(int playerId, int keyFrameIndex, int frameIndex, IRenderData operateData)
    {
        string info = $"当前逻辑:type = {operateData.GetType().ToString()},keyFrame = {keyFrameIndex},frameIndex = {frameIndex}";
        debugStringBuilder.Append(info);
        var renderData = operateData as OperateData2;
        cube2.localPosition = new Vector3(renderData.x_pos, cube2.localPosition.y, renderData.y_pos);

    }

    private void Update()
    {

    }
}

